package com.edata.bigdata.nebulasource

import org.apache.log4j.Logger

class NebulaReadConfig extends Serializable {
  @transient lazy val LOGGER = Logger.getLogger(this.getClass)
  var space = "edata"
  var label = "edata"
  var no_col = false
  var ret_col:List[String] = _
  var ngql = ""
  var limit = 10
  var partitionNum = 10

  def withSpace(space: String): NebulaReadConfig = {
    this.space = space
    this
  }

  def withLabel(label: String): NebulaReadConfig = {
    this.label = label
    this
  }

  def withNoCol(enable: Boolean): NebulaReadConfig = {
    this.no_col = enable
    this
  }

  def withRetCol(cols:List[String]): NebulaReadConfig = {
    this.ret_col = cols
    this
  }

  def withNgql(ngql: String): NebulaReadConfig = {
    this.ngql = ngql
    this
  }

  def withLimit(num: Int): NebulaReadConfig = {
    this.limit = num
    this
  }

  def withPartitionNum(num: Int): NebulaReadConfig = {
    this.partitionNum = num
    this
  }

  def build(): NebulaReadConfig = {
    check()
    this
  }

  def check(): Unit = {
    assert(space != null && !space.isEmpty, "space is empty")
    assert(label != null && !label.isEmpty, "label is empty")
    assert(limit > 0, "limit must be larger than 0")
    assert(partitionNum > 0, "partitionNum must be larger than 0")
    if(no_col&&ret_col.nonEmpty){
      LOGGER.warn(s"no_col is true, ret_col will be invalidate, and your result will contain all properties for ${label}")
    }
    if(!no_col&&ret_col.isEmpty){
      LOGGER.warn(s"no_col is false, but ret_col is empty, and your result will contain all properties for ${label}")
    }
  }
}

object NebulaReadConfig {
  def builder(): NebulaReadConfig = {
    new NebulaReadConfig
  }
}
